/*     */ package com.wgcloud.controller;
/*     */ 
/*     */ import com.wgcloud.entity.MailSet;
/*     */ import com.wgcloud.service.LogInfoService;
/*     */ import com.wgcloud.service.MailSetService;
/*     */ import com.wgcloud.util.msg.WarnMailUtil;
/*     */ import com.wgcloud.util.staticvar.StaticKeys;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.annotation.Resource;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/mailset"})
/*     */ public class MailSetController
/*     */ {
/*  35 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.controller.MailSetController.class);
/*     */ 
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private MailSetService mailSetService;
/*     */ 
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private LogInfoService logInfoService;
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"list"})
/*     */   public String MailSetList(MailSet mailSet, Model model, HttpServletRequest request) {
/*  52 */     Map<String, Object> params = new HashMap<>();
/*     */     try {
/*  54 */       List<MailSet> list = this.mailSetService.selectAllByParams(params);
/*  55 */       if (list.size() > 0) {
/*  56 */         model.addAttribute("mailSet", list.get(0));
/*     */       }
/*  58 */     } catch (Exception e) {
/*  59 */       logger.error("查询邮件设置错误", e);
/*  60 */       this.logInfoService.save("查询邮件设置错误", e.toString(), "1");
/*     */     } 
/*     */     
/*  63 */     String msg = request.getParameter("msg");
/*  64 */     if (!StringUtils.isEmpty(msg)) {
/*  65 */       if ("save".equals(msg)) {
/*  66 */         model.addAttribute("msg", "保存成功");
/*  67 */       } else if ("test".equals(msg)) {
/*  68 */         String result = request.getParameter("result");
/*  69 */         if ("success".equals(result)) {
/*  70 */           model.addAttribute("msg", "测试发送成功");
/*     */         } else {
/*  72 */           model.addAttribute("msg", "测试发送失败，请查看日志");
/*     */         } 
/*     */       } else {
/*  75 */         model.addAttribute("msg", "删除成功");
/*     */       } 
/*     */     } else {
/*  78 */       model.addAttribute("msg", "");
/*     */     } 
/*  80 */     return "mail/view";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"save"})
/*     */   public String saveMailSet(MailSet mailSet, Model model, HttpServletRequest request) {
/*     */     try {
/*  95 */       if (StringUtils.isEmpty(mailSet.getId())) {
/*  96 */         this.mailSetService.save(mailSet);
/*     */       } else {
/*  98 */         this.mailSetService.updateById(mailSet);
/*     */       } 
/* 100 */     } catch (Exception e) {
/* 101 */       logger.error("保存邮件设置信息错误", e);
/* 102 */       this.logInfoService.save("保存邮件设置信息错误", e.toString(), "1");
/*     */     } 
/* 104 */     return "redirect:/mailset/list?msg=save";
/*     */   }
/*     */   
/*     */   @RequestMapping({"test"})
/*     */   public String test(MailSet mailSet, Model model, HttpServletRequest request) {
/* 109 */     String result = "success";
/*     */     try {
/* 111 */       if (StringUtils.isEmpty(mailSet.getId())) {
/* 112 */         this.mailSetService.save(mailSet);
/*     */       } else {
/* 114 */         this.mailSetService.updateById(mailSet);
/*     */       } 
/* 116 */       StaticKeys.mailSet = mailSet;
/* 117 */       result = WarnMailUtil.sendMail(mailSet.getToMail(), "测试邮件发送", "测试邮件发送");
/* 118 */     } catch (Exception e) {
/* 119 */       logger.error("测试邮件设置信息错误", e);
/* 120 */       this.logInfoService.save("测试邮件设置信息错误", e.toString(), "1");
/*     */     } 
/* 122 */     return "redirect:/mailset/list?msg=test&result=" + result;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"del"})
/*     */   public String delete(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
/* 136 */     String errorMsg = "删除告警邮件设置错误";
/*     */     try {
/* 138 */       if (!StringUtils.isEmpty(request.getParameter("id"))) {
/* 139 */         this.mailSetService.deleteById(request.getParameter("id").split(","));
/*     */       }
/* 141 */     } catch (Exception e) {
/* 142 */       logger.error(errorMsg, e);
/* 143 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/*     */     
/* 146 */     return "redirect:/mailset/list?msg=del";
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/controller/MailSetController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */